package com.frxuexi.park2305

import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.activity.viewModels
import androidx.navigation.findNavController
import androidx.navigation.ui.NavigationUI
import com.alibaba.android.arouter.facade.annotation.Route
import com.blankj.utilcode.util.ToastUtils
import com.frxuexi.lib_base.mvi.BaseViewActivity
import com.frxuexi.lib_base.utils.LiveDataBus
import com.frxuexi.park2305.databinding.ActivityMainBinding
import dagger.hilt.android.AndroidEntryPoint
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

@AndroidEntryPoint
@Route(path = "/app/MainActivity")
class MainActivity : BaseViewActivity<ActivityMainBinding>() {
    override val binding: ActivityMainBinding by lazy { ActivityMainBinding.inflate(layoutInflater) }

    override fun initView() {
        EventBus.getDefault().register(this)
        val navController = findNavController(R.id.fragment_main)
        NavigationUI.setupWithNavController(binding.nav,navController)

        binding.nav.getOrCreateBadge(R.id.shopFragment).apply {
            backgroundColor=Color.RED
            badgeTextColor=Color.WHITE
            number=10
        }

        binding.nav.menu.findItem(R.id.shopFragment).setOnMenuItemClickListener {
            binding.nav.removeBadge(R.id.shopFragment)
            return@setOnMenuItemClickListener false
        }

        /*LiveDataBus.with("msg",String::class.java).observe(this){
            if(it=="3"){
                binding.nav.selectedItemId=R.id.cartFragment
            }
        }*/

    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    fun getMsg(num:String){
        ToastUtils.showLong(num)
        if(num=="3"){
            binding.nav.selectedItemId=R.id.cartFragment
        }
    }

}